<?php
/**
 * File
 *
 * TO DOC
 *
 * @author  Badrus Said <badrus.said@gmail.com>
 * @protected
 * @singleton
 */
final class api_File extends Wrapper {
    public function readdirs($a, $b = null) {static $r = array();
        if (false !== ($f = opendir($a))) {
            while(false !== ($i = readdir($f))) {
                if ($i == "." || $i == "..") continue;
                $j = $a . $i;
                if (is_dir($j)) {
                    $this->readdirs($j.FILE_SEPARATOR, $b);
                    continue;
                } else {
                if (is_null($b) || (!is_null($b) && (substr($j, -4) == $b))) {
                    $r[] = $j;
                }}
            } closedir($f);
        } $rs = $r; unset($r);
        return $rs;
    }
    public function rmdirs($a) {
        if (false !== ($f = opendir($a))) {
            while(false !== ($i = readdir($f))) {
                if ($i == "." || $i == "..") continue;
                $j = $a.$i;
                (is_dir($j)) ? $this->rmdirs($j.FILE_SEPARATOR) : unlink($j);
            }  closedir($f);
        }
        return rmdir($a);
    }
    public function drives() {
        $i = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $j = strlen($i);
        $k = array();
        for($l = 0; $l < $j; $l++) {
            if (is_dir($i[$l].":\\")) array_push($k, $i[$l]);
        }
        return $k;
    }
}
?>